<?php
require_once(dirname(__FILE__)."../../users/config.php");
require_once("kill.php");
session_start();
$aid = isset($aid) && is_numeric($aid) ? $aid : 0;
$AdultNum = isset($AdultNum) && is_numeric($AdultNum) ? $AdultNum : 0;

if(!defined('wwwew023com'))
{
ShowMsg("引入文件错误",'/');
exit();
	
}
if($aid=='0' or $AdultNum=='0')
{
ShowMsg("参数错误",'/');
exit();
	
}
if(!$_COOKIE)
{
ShowMsg("您的浏览器关闭了COOKIE,请打开浏览器的COOKIE后再预定",'-1');
exit();
	
}

$_SESSION['buyidd']='188_'.$aid.'XL';

if($_SESSION['188yuding']<>'gogo')
{
ShowMsg("错误，请不要越级操作",'/');
exit();
	
}



if($_COOKIE['buydd']=='188_'.$aid.'XL')
{
ShowMsg("您已经提交了数据，请不要重复刷新",'-1');
exit();
	
}







$buyid = '188_'.$aid.'XL'.mt_rand(1,99);

if(!$cfg_ml->IsLogin())
{ //如果没有登录

	    $row = $dsql->GetOne("Select mid From `#@__member` where mb='$contact_mobile' ");
		if(!is_array($row))
		{ //如果手机号码没有注册，则注册
		$rrss='Y';
		$jointime = time();
		$joinip = GetIP();	
		$pwd = md5($contact_mobile);
		$inQuery2 = "INSERT INTO `#@__member` (`pwd` ,`rank` ,`money` ,`jointime`, `joinip` ,`logintime`,`loginip`,`checkmail`,`mb`,`tjr`,`tel`,`email`)
	   VALUES ('$pwd','10','0',
	   '$jointime','$joinip','$jointime','$joinip','$checkmail','$contact_mobile','$tjr','$contact_phone','$contact_email'); ";
	   
	   if(!$dsql->ExecuteNoneQuery($inQuery2))
		{
			$gerr = $dsql->GetError();
			ShowMsg("把数据保存到数据库时出错<br>error:{$gerr}，请联系管理员！","javascript:;");
			exit();	
		}
		
		
			
		}
//----------------------------------------------
//模拟登录
//---------------------------
			$cfg_ml = new MemberLogin(7*3600);
			$rs = $cfg_ml->CheckUser($contact_mobile, $contact_mobile);
		
}

$time=time();
$ip=getip();
		$inquery = "INSERT INTO `#@__order`(title,id,mid,buyid,ip,time,name,mb,tel,mail,jj,jiage,cr,rt,zcc) Values('$title','$aid','".$cfg_ml->M_ID."','$buyid','$ip','$time','$contact_name','$contact_mobile','$contact_phone','$contact_email','$order_comment','$totalPrice','$AdultNum','$KidNum','$thisTime')";
		if(!$dsql->ExecuteNoneQuery($inquery))
		{
			$gerr = $dsql->GetError();
			ShowMsg("把数据保存到数据库时出错<br>error:{$gerr}，请联系管理员！","javascript:;");
			exit();
		}
		else
		{
		//写入cookie	
		$pid='188_'.$aid.'XL';
		setcookie("buydd",$pid,time()+3600);
		
		}

		

// 写入抵用券
$dyyq = $dsql->GetOne("Select dyq From `#@__line` where aid='$aid'"); //得到抵用券
$xldyq=$dyyq['dyq'];
$xldyq= isset($xldyq) && is_numeric($xldyq) ? $xldyq : 0;

if($xldyq<>'0')
{
$inqueryo = "INSERT INTO `#@__member_pms`(fromid,toid,subject,sendtime,writetime,hasview) Values('$aid','".$cfg_ml->M_ID."','$xldyq','$time','','')";  // 线路ID，会员ID，抵用券金额，获取时间,使用时间,状态 (管理员确认)

if(!$dsql->ExecuteNoneQuery($inqueryo))
{
			$gerr = $dsql->GetError();
			ShowMsg("把数据保存到数据库时出错<br>error:{$gerr}，请联系管理员！","javascript:;");
			exit();
}
		
}

        $tongz='系统管理员关闭了手机短信通知';
        $makk=$dsql->getone("select mb_2,mb_8_c from #@__mb where aid='0'");
		$mak1=$dsql->getone("select mb_1 from #@__mb where aid='1'");
		if($makk['mb_2']=='1')
		{ // 发送短信
		$ombb=okmbb($aid,$buyid);
		$tongz=$ombb;
		}	
		if($makk['mb_8_c']=='1')
		{ // 发送短信至管理员
		$adminmb=adminmb($aid,$buyid);
		}		
		if($mak1['mb_1']=='1' && $contact_email<>'')
		{ // 发送邮件
		$omb1=sendline($contact_email,$passwd,$contact_mobile,$aid);
		}

//$sql = "select * from #@__hotel where aid='$aid'";
//$dsql->SetQuery($sql);
//$dsql->Execute();
//$row = $dsql->GetArray();
$dpl = new DedeTemplate();
$tpl =$cfg_basedir.$cfg_templets_dir.'/default/188_order_2.htm';
$dpl->LoadTemplate($tpl);
$dpl->display();
?>